
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" id="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1, initial-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="format-detection" content="telephone=yes" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta charset="utf-8">
    <title>{{config("site.title")}}</title>
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <div id="wx_logo" style="display: none">
        <img src="{{asset('image/weixin.jpg')}}">
    </div>
</head>

<body>
<header>
    <span class="app_Larrow"><a href="{{url('appdetail')}}"><img src="image/app_jiantou.png"/></a></span>
    <p class="app_upload_tit">参赛报名信息</p>
</header>

<ul class="app_partner">
    <li>
        <span><b>*</b>作品名称</span>
        <input id="name" type="text" class="text" data-msg-required="">
    </li>
    <li>
        <span><b>*</b>拍摄地点</span>
        <input id="pic_address" type="text" class="text" data-msg-required="">
    </li>

    <li>
        <span><b>*</b>拍摄时间</span>
        <input id="add_time" placeholder="2016-06-29" type="date"  class="text" data-msg-required="">
    </li>
    <li>
        <span><b>*</b>上传照片</span>
        <a href="javascript:;" id="pickfiles" class="pickfiles" title="选择图片">
            <input id="pic" type="hidden" value="{{isset($key) ? $key :""}}"/>
            <img style="width: 80%;" src="{{url("images/defaltPic.jpg")}}" onerror="this.src='{{url("images/defaltPic.jpg")}}'"/>
        </a>
    </li>
    <li>
        <span><b>*</b>作者姓名</span>
        <input id="author" type="text" class="text" data-msg-required="">
    </li>
    <li>
        <span><b>*</b>作者地址</span>
        <input id="authoraddress" type="text" class="text" data-msg-required="">
    </li>
    <li>
        <span><b>*</b>手机号码</span>
        <input id="mobile" type="text" class="text" data-msg-required="">
    </li>
    <li>
        <a href="javascript:void(0);" id="confirm" class="btn">提交</a>
    </li>
</ul>
</body>

<script src="{{asset('/js/jquery-1.9.1.js')}}" type="text/javascript"></script>
<script src="{{asset('/js/common.js')}}" type="text/javascript"></script>
<script src="{{ asset('/js/plupload/plupload.full.min.js') }}"></script>
<script type="text/javascript" language="JavaScript">
    $(function () {
        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'pickfiles', // you can pass in id...
            //container: document.getElementById('container'), // ... or DOM Element itself
            url: "{{ url('upimg') }}",
            filters: {
                max_file_size: '20mb',
                mime_types: [
                    {title: "Image files", extensions: "jpg,gif,png,JPG,JPEG,PNG,GIF"}
                ]
            },
            multi_selection: false,
            file_data_name: 'file',
            multipart_params: {'_token': '{{ csrf_token() }}', 'dir': '{{$type}}'},
            // Flash settings
            flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
            // Silverlight settings
            silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
            init: {
                PostInit: function () {
                    return false;
                },
                FilesAdded: function (up, file) {
                    $('.pickfiles img').attr('src', '{{ asset('images/loading.gif') }}');
                    uploader.start();
                },
                Error: function (up, err) {
                    $.alert("Error:" + err.message);
                },
                FileUploaded: function (up, file, responseObj) {
                    var response = $.parseJSON(responseObj.response);
                    if (response.state == 'success') {
                        __type = "{{$type}}";
                        $('.pickfiles img').attr('src', '{!! url("img/'+__type+'-' + response.id + '/290-165") !!}');
                        $('.pickfiles input').val(response.id);
                    } else {
                        $.alert("FileUploadedError:" +response.message);
                    }
                }
            }
        });
        uploader.init();


        //上传作品
        $("#confirm").on("click", function(){
            if('' == $("#name").val()){
                $.alert("请填写作品名称");
                return;
            }
            if('' == $("#pic_address").val()){
                $.alert("请填写拍摄地点");
                return;
            }
            if('' == $("#add_time").val()){
                $.alert("请填写拍摄时间");
                return;
            }
            if('' == $("#pic").val()){
                $.alert("请上传作品");
                return;
            }
            if('' == $("#author").val()){
                $.alert("请填写作者姓名");
                return;
            }
            if('' == $("#authoraddress").val()){
                $.alert("请填写作者地址");
                return;
            }
            if('' == $("#mobile").val()){
                $.alert("请填写手机号");
                return;
            }

            var postData = {
                name:$("#name").val(),
                pic_address:$("#pic_address").val(),
                add_time:$("#add_time").val(),
                add_month:$("#add_month").val(),
                pic:$("#pic").val(),
                author:$("#author").val(),
                authoraddress:$("#authoraddress").val(),
                mobile:$("#mobile").val(),
                _token:"{{ csrf_token() }}"
            };
            $.ajax({
                type:"POST",
                url:"{{url('uploadwork')}}",
                async:true,
                headers:{  },
                data:postData
            }).done(function(data){
                $.alert(data.message, function () {
                    if('success' == data.state){
                        window.location.href = '{{url('appindex')}}';
                    }
                });
            }).fail(function(){

            }).always(function(){
                $.alert(data.message);
            });
        });
    });
</script>
</html>